import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import {resolve, join} from "path";
import {readdirSync} from "fs";
// https://vitejs.dev/config/
function pathResolve(dir) {
  return resolve(process.cwd(), ".", dir);
}
const entryPath = resolve(__dirname, "./src/pages");
const pages = readdirSync(entryPath).reduce((obj, dirname) => {
  obj[dirname] = join(entryPath, `${dirname}/index.html`);
  return obj;
}, {});
export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      input: {...pages}
    }
  },
  //打包相对路径(多页面配置)
  experimental: {
    renderBuiltUrl: (filename,params) => {
      console.log('filename',filename)
      return `../../../${filename}`
    }
  }
})
